using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for DAL
/// </summary>
public class DAL
{
	
    private static string _strConn = ConfigurationManager.ConnectionStrings["Capstone"].ConnectionString;
    public static bool Login(string username, string password)
    {
        int results = 0;

        using (SqlConnection sqlConn = new SqlConnection(_strConn))
        {
            sqlConn.Open();
            using (SqlCommand sqlCmd = new SqlCommand("usp_Login", sqlConn))
            {
                // This is needed if you are using stored procedures.  If not, use the default
                // CommandType.Text enumeration
                sqlCmd.CommandType = CommandType.StoredProcedure;

                // These two parameters are needed and are by default INPUT parameters
                sqlCmd.Parameters.Add("@username", SqlDbType.VarChar, 64).Value = username;
                sqlCmd.Parameters.Add("@password", SqlDbType.VarChar, 64).Value = password;

                // This parameter has to be declared as an output parameter.  It will either be 1 or 0
                // which indicates success/failure to login to the database
                sqlCmd.Parameters.Add("@results", SqlDbType.Int).Direction = ParameterDirection.Output;

                results = sqlCmd.ExecuteNonQuery();

                results = (int)sqlCmd.Parameters["@results"].Value;

            }
        }

        if (results == 0)
            return false;

        return true;
    }
}
